/*
 * Serial.h
 *
 *  Created on: Jan 14, 2014
 *      Author: ppks
 */

#ifndef SERIAL_H_
#define SERIAL_H_

/********************************************************************************/
/* Hardware Dependent Defines                                                   */
/********************************************************************************/
/* Number of available UARTs in hardware */
#if defined(MEGA)
  #define UART_NUMBER 4
#elif defined(PROMICRO)
  #define UART_NUMBER 2
#else
  #define UART_NUMBER 1
#endif

/* RX and TX buffer size */
#if defined(GPS_SERIAL_ENABLED)
  #define RX_BUFFER_SIZE 256 /* 256 RX buffer is needed for GPS communication (64 or 128 was too short) */
#else
  #define RX_BUFFER_SIZE 64
#endif
#define TX_BUFFER_SIZE 128

/********************************************************************************/
/* Exported Functions Prototypes                                                */
/********************************************************************************/
void CommSerial_Open(uint8_t port, uint32_t baud);
void CommSerial_Close(uint8_t port);
void CommSerial_SendData(uint8_t port);
void CommSerial_StoreDataInBuffer(uint8_t data, uint8_t portnum);
uint8_t CommSerial_ReadByteFromBuffer(uint8_t port);
uint8_t CommSerial_IsNewDataAvailable(uint8_t port);
uint8_t CommSerial_GetTXBuffSizeUsed(uint8_t port);
bool CommSerial_IsTXCompleted(uint8_t port);
void CommSerial_WriteByteToBuffer(uint8_t port,uint8_t c);
void CommSerial_WriteBlockToBuffer(uint8_t port, uint8_t *data);
void CommSerial_SendUint8(uint8_t port,uint8_t c);
void CommSerial_SendUint16(uint8_t port,uint16_t c);
void CommSerial_SendUint32(uint8_t port,uint32_t c);
void CommSerial_WriteCRLF(uint8_t port);

#endif /* SERIAL_H_ */
